// 作者:于大明
// 职责：只存放api的请求的接口的数据

//-------------------------Service引入----------------------------------
import MBProduct from '@/service/07MB/MBProductAppService.js';

let mixinApi = {
	// 负责程序中需要进行set的数据 就是页面交互需要改的数据 比如点击checkbox 需要设置true false 和存放ajax的输入输出 (尽量少去定义data里面的属性 多用computed或者filters或者组件进行处理) 
	// 1 能不能在页面单行代码实现
	// 2 能不能不用data methods去实现这个功能
	data() {
		let getProductLstIn = {
				productName: "",
				pageIndex: 1,
				productType: "0",
				productOrerType: "0",
				productServiceType: 10,
				pageSize: 20,
				isPullDown:false
			};
		let queryObj = this.$util.getQueryObj();
		if (queryObj) {
			getProductLstIn = Object.assign(getProductLstIn, queryObj);
		}
		
		// const vuex_GoBackObj = store.state.vuex_GoBackObj;
		// if (vuex_GoBackObj && vuex_GoBackObj.pageIndex) {
		// 	vuex_GoBackObj.pageSize = vuex_GoBackObj.pageIndex * pageSize;
		// 	vuex_GoBackObj.pageIndex = 1;
		// 	getProductLstIn = Object.assign(getProductLstIn, vuex_GoBackObj);
		// }
		
		return {
			//---------------------接口输入输出 接口名称+in/out 命名 列如接口名称是getStudentList----------------------
			getProductLstIn: getProductLstIn,
			getProductLstOut: {
				datas: [],
				rowCount:0,
			},
			// -------------------------Url的参数获取-----------------------------------------------------------------
			queryObj: {
				id: '' // 参数描述
			},
		};
	},
	// 负责和页面事件进行交互
	methods: {
		async getProductLst() {
			for (let i = 0; i < 20; i++) {
			    this.getProductLstOut.datas.push({id:null});
			}
			
			let myPageList = await MBProduct.GetProductLst(this.getProductLstIn, null, null, false);
			myPageList.datas.forEach(item => item.getProductLstIn = this.$util.deepCopy(this.getProductLstIn));
			this.getProductLstOut.datas=this.getProductLstOut.datas.filter(x=>x.id); // 去掉加载效果
			this.statusLoadMore = "more"
			
			// 第一次加载
			if (this.getProductLstIn.pageIndex == 1) {
				uni.pageScrollTo({
					scrollTop: 0
				})
				this.getProductLstOut = myPageList;
			} else if (this.getProductLstOut.rowCount > this.getProductLstOut.datas.length) {
				this.getProductLstOut.datas.push(...myPageList.datas);
			}
			
			if (this.getProductLstOut.datas.length == 0) {
				this.statusLoadMore = "no-more"
			} else if (this.getProductLstOut.datas.length <= 6) {
				this.statusLoadMore = "";
			} else if (this.getProductLstOut.rowCount <= this.getProductLstOut.datas.length) {
				this.statusLoadMore = "no-more"
			}
			
			uni.stopPullDownRefresh();
			const vuex_GoBackObj = getApp().globalData.VuePrototype.$store.state.vuex_GoBackObj;
			if (vuex_GoBackObj) {
				let hdItem = this.getProductLstOut.datas.find(x => x.id == vuex_GoBackObj
					.MBProductId);
				if (hdItem) hdItem.select = true;
				getApp().globalData.VuePrototype.$u.vuex('vuex_GoBackObj', null);
			}
			this.$nextTick(() => {
				if (vuex_GoBackObj) {
					uni.pageScrollTo({
						scrollTop: vuex_GoBackObj.scrollTop,
						duration: 300
					})
				}
			});
		}
	},
}
export default mixinApi;